package com.mzj.saas.mservice.backlog.repository;

import com.mzj.saas.mservice.backlog.entity.BacklogItemApprove;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface BacklogItemApproveRepository extends PagingAndSortingRepository<BacklogItemApprove, Long>, JpaSpecificationExecutor<BacklogItemApprove> {
    BacklogItemApprove findByBacklogItemId(Long backlogItemId);

    BacklogItemApprove findByApplyAuditId(Long applyAuditId);

    List<BacklogItemApprove> findByApplyId(Long applyId);

    int deleteByApplyId(Long applyId);

    List<BacklogItemApprove> findByApplyAuditIdAndStatus(Long applyAuditId, Integer status);

    List<BacklogItemApprove> findByApplyIdAndApplyAuditId(Long applyId, Long applyAuditId);

    @Modifying
    @Query(value = "UPDATE `saas_backlog_item_approve` SET apply_id_old = ?2 WHERE apply_id = ?1 and apply_id_old is null ", nativeQuery = true)
    int updateApplyIdOldByApplyId(Long applyId, Long applyIdOld);
}
